package com.eam.job.controller;

import com.eam.common.controller.BaseController;
import com.eam.common.utils.ExcelUtil;
import com.eam.core.annotation.Log;
import com.eam.core.core.AjaxResult;
import com.eam.core.enums.BusinessType;
import com.eam.job.domain.EamClassify;
import com.eam.job.service.IEamClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 分类Controller
 * 
 * @author eam
 * @date 2022-03-23
 */
@RestController
@RequestMapping("/eam/classify")
public class EamClassifyController extends BaseController
{
    @Autowired
    private IEamClassifyService eamClassifyService;

    /**
     * 查询分类列表
     */
    @PreAuthorize("@ss.hasPermi('eam:classify:list')")
    @GetMapping("/list")
    public AjaxResult list(EamClassify eamClassify)
    {
        List<EamClassify> list = eamClassifyService.selectEamClassifyList(eamClassify);
        return AjaxResult.success(list);
    }

    /**
     * 导出分类列表
     */
    @PreAuthorize("@ss.hasPermi('eam:classify:export')")
    @Log(title = "分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EamClassify eamClassify)
    {
        List<EamClassify> list = eamClassifyService.selectEamClassifyList(eamClassify);
        ExcelUtil<EamClassify> util = new ExcelUtil<EamClassify>(EamClassify.class);
        util.exportExcel(response, list, "分类数据");
    }

    /**
     * 获取分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('eam:classify:query')")
    @GetMapping(value = "/{classifyId}")
    public AjaxResult getInfo(@PathVariable("classifyId") Long classifyId)
    {
        return AjaxResult.success(eamClassifyService.selectEamClassifyByClassifyId(classifyId));
    }

    /**
     * 新增分类
     */
    @PreAuthorize("@ss.hasPermi('eam:classify:add')")
    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EamClassify eamClassify)
    {
        return toAjax(eamClassifyService.insertEamClassify(eamClassify));
    }

    /**
     * 修改分类
     */
    @PreAuthorize("@ss.hasPermi('eam:classify:edit')")
    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EamClassify eamClassify)
    {
        return toAjax(eamClassifyService.updateEamClassify(eamClassify));
    }

    /**
     * 删除分类
     */
    @PreAuthorize("@ss.hasPermi('eam:classify:remove')")
    @Log(title = "分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{classifyIds}")
    public AjaxResult remove(@PathVariable Long[] classifyIds)
    {
        return toAjax(eamClassifyService.deleteEamClassifyByClassifyIds(classifyIds));
    }
}
